import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;


public class testWindow {

	private JFrame frmCs;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					testWindow window = new testWindow();
					window.frmCs.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public testWindow() {
		initialize();
	}
	
	int count;
	JLabel lblMode;
	JLabel lblSpeed;
	JLabel lblFunctionDisplay;
	JButton btnStartstop;
	JButton btnMode;
	java.util.Timer timer;
	
	private Vector<FunctionMode> modes = new Vector<FunctionMode>();		
	int currentMode = 0;
	boolean isActive = false; 
	
	class FormUpdater extends TimerTask {
        public void run(){
        	count++;
            lblSpeed.setText(Integer.toString(count));
            if(!isActive) return;
            if(modes.size() == 0 || currentMode >= modes.size()) return;
            FunctionMode.rotations += 1;
            if (FunctionMode.rotations == 15) FunctionMode.rotations = 0;
            FunctionMode.time = 1;  
            for (FunctionMode mode : modes) {
				mode.Compute();
			}
            lblFunctionDisplay.setText(modes.get(currentMode).GetDisplayString());
        }
    }
	
	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		count = 0;
		frmCs = new JFrame();
		timer = new Timer();
		timer.schedule(new FormUpdater(), 1000, 1000);
		frmCs.setTitle("CS846");
		frmCs.setResizable(false);
		frmCs.setBounds(100, 100, 285, 260);
		frmCs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frmCs.getContentPane().setLayout(null);
		
		lblMode = new JLabel("");
		lblMode.setBounds(38, 51, 89, 38);
		frmCs.getContentPane().add(lblMode);
		
		lblSpeed = new JLabel("0");
		lblSpeed.setBounds(197, 51, 46, 14);
		frmCs.getContentPane().add(lblSpeed);
		
		lblFunctionDisplay = new JLabel("");
		lblFunctionDisplay.setBounds(145, 111, 98, 14);
		frmCs.getContentPane().add(lblFunctionDisplay);
		
		btnStartstop = new JButton("StartStop");
		btnStartstop.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				isActive = !isActive;
			}
		});
		
		btnStartstop.setBounds(154, 162, 89, 23);
		frmCs.getContentPane().add(btnStartstop);
		
		btnMode = new JButton("Mode");
		btnMode.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(modes.size() == 0) return;
				currentMode++;
				if(currentMode == modes.size()) currentMode = 0;
				lblMode.setText(modes.get(currentMode).ModeName());
			}
		});
		
		btnMode.setBounds(38, 162, 89, 23);
		frmCs.getContentPane().add(btnMode);
		
		modes.add(new Speed());modes.add(new MaxSpeed());

		lblMode.setText(modes.get(currentMode).ModeName());
	}
}
